﻿using System;
using System.Globalization;
using System.Windows;
using N3P.WCF.Proxyless;
using ServiceContracts;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();

            //Uncomment the line below to demand that the client's definition be created now, this is a "fire and forget" style async call
            //WcfClient<IService1>.CreateClientAsync();
        }

        private void ButtonClick(object sender, RoutedEventArgs e)
        {
            var client = new WcfClient<IService1>();
            client.Call(x => x.ProcessString(MyTextBox.Text), WriteToTextBlock);
        }

        public void WriteToTextBlock(string text, Exception exception)
        {
            MyTextBlock.Text = exception != null ? exception.Message : text;
        }


        public void WriteToTextBlock(DateTime date, Exception exception)
        {
            MyTextBlock.Text = exception != null ? exception.Message : date.ToShortDateString();
        }

        public void WriteToTextBlock(int number, Exception exception)
        {
            MyTextBlock.Text = exception != null ? exception.Message : number.ToString(CultureInfo.InvariantCulture);
        }
    }
}
